<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <link rel="stylesheet" href="/js/plugins/treeview/bootstrap-treeview.min.css" type="text/css">
    <script type="text/javascript" src="/js/plugins/treeview/bootstrap-treeview.min.js"></script>
    <script type="text/javascript" src="/js/plugins/ckeditor/ckeditor.js"></script>
    <script>
        $(function () {
            $('.inputBtn').click(function () {
                var obj = $(this).data('json');
                $('#inputForm input').val('');
                if (obj) {
                    $("#inputForm input[name='id']").val(obj.id);
                    $("#inputForm input[name='coverUrl']").val(obj.coverUrl);
                    $("#inputForm input[name='name']").val(obj.name);
                    $("#inputForm input[name='integral']").val(obj.integral);
                    $('#coverUrl').prop('src', obj.coverUrl);
                }
                $('#inputModal').modal('show');
            });
            $('.inputSubmit').click(function () {
                $('#inputForm').submit();
            });
            $('.deleteBtn').click(function () {
                var url = $(this).data("url");
                var id = $(this).data("id");
                $.get(url,{id:id},function (data) {
                    if (data.success){
                        location.reload();
                    }
                });
            });

        });
    </script>
</head>
<body>
<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#assign currentMenu = "commodity" />
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">商品信息管理</h1>
                </div>
            </div>
            <form class="form-inline" id="searchForm" action="/commodity/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label for="keyword">商品搜索:</label>
                    <input type="text" class="form-control" id="keyword" name="keyword" value="${(qo.keyword)!}"
                           placeholder="请输入商品名称">
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a class="btn btn-success inputBtn">
                    <span href="javascript:" class="glyphicon glyphicon-plus"></span> 添加商品
                </a>
            </form>
            <div class="row">
                <table class="table table-striped table-hover">
                    <tr>
                        <th>名称</th>
                        <th>封面</th>
                        <th>积分</th>
                        <th>销量</th>
                        <th>操作</th>
                    </tr>
                        <#list pageInfo.list as entitry>
                        <tr>
                            <td>${entitry.name}</td>
                            <td><img src="${entitry.coverUrl}" width="50px"></td>
                            <td>${entitry.integral}</td>
                            <td>${entitry.salesVolume}</td>
                            <td>
                                <a data-json='${entitry.json}'
                                   class="btn btn-info btn-xs inputBtn" href="javascript:">
                                    <span class="glyphicon glyphicon-pencil"></span>修改
                                </a>
                                <a data-id="${entitry.id}"
                                   href="javascript:" data-url="/commodity/delete.do" class="btn btn-danger btn-xs deleteBtn" >
                                    <span class="glyphicon glyphicon-trash "></span>删除
                                </a>
                            </td>
                        </tr>
                        </#list>
                </table>
                <#include "../common/page.ftl">
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/commodity/saveOrUpdate.do" method="post"
                      id="inputForm" enctype="multipart/form-data">
                    <input type="hidden" name="id">
                    <input type="hidden" name="coverUrl"/>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">商品名称：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="name"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6 coverUrl">
                            <img id="coverUrl" width="100%">
                            <input type="file" class="form-control" name="file">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">积分：</label>
                        <div class="col-lg-6">
                            <input type="number" class="form-control"  name="integral"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary inputSubmit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>